<?php
/**
 * Created by PhpStorm.
 * User: CY
 * Date: 2018/3/7
 * Time: 8:45
 */

namespace app\api\validate;


class IDCollection extends BaseValidate
{
    protected $rule = [
        'ids' => 'require|checkIDs'
    ];

    protected $message = [
        'ids' => 'ids参数必须为以英文逗号分隔的多个正整数'
    ];

    protected function checkIDs($value){
        $values = explode(',',$value);
        if(empty($values)){
            return false;
        }else{
            foreach ($values as $id){
                if(!$this->isPositiveInteger($id)){
                    // 所有的id都必须是正整数
                    return false;
                }
            }
            return true;
        }
    }
}